package com.inhim.pjhim.utils;

import android.content.Context;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.library.flowlayout.FlowLayoutManager;
import com.library.flowlayout.SpaceItemDecoration;

import org.yczbj.ycrefreshviewlib.view.YCRefreshView;

public class RecylerViewUtils {
    public static final String VERTICAL = "vertical";
    public static final String HORIZONTAL = "horizontal";
    public static final String GRID = "grid";
    public static final String UNSET_GRID = "unset_grid";
    public static final int SPAN_COUNT = 4;
    private static final int ITEM_EDGE_PADDING = 12;
    public static void attachLinearRv(Context mContext,RecyclerView rv, String typeManager,int position) {
        LinearLayoutManager mLayoutManager;
        GridLayoutManager gridLayoutManager;
        switch (typeManager) {
            case VERTICAL:
                mLayoutManager=new LinearLayoutManager(mContext);
                rv.setLayoutManager(mLayoutManager);
                //设置增加或删除条目的动画
                mLayoutManager.scrollToPositionWithOffset(position, 0);
                break;
            case HORIZONTAL:
                mLayoutManager= new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL, false);
                rv.setLayoutManager(mLayoutManager);
                //设置增加或删除条目的动画
                mLayoutManager.scrollToPositionWithOffset(position, 0);
                break;
            case GRID:
                gridLayoutManager = new GridLayoutManager(mContext, 4);
                rv.setLayoutManager(gridLayoutManager);
                break;
            default:
                break;
        }
        rv.setItemAnimator(new DefaultItemAnimator());
    }

    public static void attachGridLayoutRv(Context mContext, RecyclerView rv, String typeManager) {
        GridLayoutManager gridLayoutManager;
        switch (typeManager) {
            case GRID:
                gridLayoutManager = new GridLayoutManager(mContext, 4);
                rv.setLayoutManager(gridLayoutManager);
                break;
            case UNSET_GRID:
                FlowLayoutManager flowLayoutManager = new FlowLayoutManager();
                //设置每一个item间距
                rv.addItemDecoration(new SpaceItemDecoration(Utils.dip2px(mContext,10)));
                rv.setLayoutManager(flowLayoutManager);
                break;
            default:
                break;
        }
        rv.setItemAnimator(new DefaultItemAnimator());
    }

    public static void attachGridLayoutRv(Context mContext, YCRefreshView rv, String typeManager) {
        GridLayoutManager gridLayoutManager;
        switch (typeManager) {
            case GRID:
                gridLayoutManager = new GridLayoutManager(mContext, 4);
                rv.setLayoutManager(gridLayoutManager);
                break;
            case UNSET_GRID:
                FlowLayoutManager flowLayoutManager = new FlowLayoutManager();
                //设置每一个item间距
                rv.addItemDecoration(new SpaceItemDecoration(Utils.dip2px(mContext,10)));
                rv.setLayoutManager(flowLayoutManager);
                break;
            default:
                break;
        }
        rv.setItemAnimator(new DefaultItemAnimator());
    }
}
